package com.yzl.springboot.springboot.mapper;

import com.yzl.springboot.springboot.domain.User;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Title: UserMapper
 * @Author: 姚志立
 * @Description:
 * @Date: 2020/5/24 9:36
 * @Version: 1.0
 */

@Repository
public class UserMapper implements Serializable {
    private static Map<String, User>userMap=new HashMap<>();
    static {
        userMap.put("jack", new User(1,"jack","123"));
        userMap.put("tom", new User(2,"tom","1234"));
        userMap.put("jone", new User(3,"jone","12345"));
    }

    public User login(String username,String pwd){
        User user = userMap.get(username);
        if(user==null){
            return null;
        }
        if(user.getPwd().equals(pwd)){
            return user;
        }
        return null;
    }

    public List<User>listUser(){
        List<User> list = new ArrayList<>();
        list.addAll(userMap.values());

        return list;
    }
}
